package com.glory.dmegcpda.viewmodel

import com.glory.dmegcpda.model.WeldingRepository
import com.glory.mvvmnet.base.BaseViewModel
import com.glory.mvvmnet.entity.CallObserveBean
import com.glory.mvvmnet.entity.ToastMessageBean
import com.google.gson.JsonObject

class WeldingViewModel : BaseViewModel() {
    val weldingRepository by lazy {WeldingRepository()}
    fun initEqpData(id: String) {
        val bodyMap = JsonObject()
        bodyMap.addProperty("ENTITYMODEL", "com.glory.mes.ras.eqp.PositionSetLine")
        bodyMap.addProperty("WHERECLAUSE", "positionName='"+id+"'")
        launchOnlyResult({
            val scribingeqp = weldingRepository.scribingEqp(bodyMap)
            if (scribingeqp.dATALIST.isNotEmpty()){
                defUI.callObserve.value = CallObserveBean(1,scribingeqp)
            }else{
                defUI.toastEvent.value = ToastMessageBean("无返回数据，请检查输入信息是否正确？",true)
            }
        })
    }

    fun initBoxData(id: String) {
        val bodyMap = JsonObject()
        bodyMap.addProperty("ENTITYMODEL", "com.glory.mes.mm.lot.model.MLot")
        bodyMap.addProperty("WHERECLAUSE", "durable='"+id+"'")
        launchOnlyResult({
            val scribingbox = weldingRepository.scribingBox(bodyMap)
            if (scribingbox.dATALIST.isNotEmpty()){
                defUI.callObserve.value = CallObserveBean(2,scribingbox)
            }else{
                defUI.toastEvent.value = ToastMessageBean("无返回数据，请检查输入信息是否正确？",true)
            }
        })
    }

    fun initData(eqpCode: String, boxCode: String) {
        val bodyMap = JsonObject()
        bodyMap.addProperty("POSITIONNAME", eqpCode+"#POSITIONNAME")
        bodyMap.addProperty("DURABLEID", boxCode)
        launchOnlyResult({
            weldingRepository.welbing(bodyMap)
            defUI.callObserve.value = CallObserveBean(0)
        })
    }

}